define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'user/index',
        add_url: 'user/add',
        edit_url: 'user/edit',
        delete_url: 'user/delete',
        export_url: 'user/export',
        quanxian: 'user/quanxian',
        tuijian: 'user/tuijian',
        removeVip: 'user/removeVip',
        celarAllUserBlackList: 'user/celarAllUserBlackList',
        removeVipAll: 'user/removeVipAll',
        celarAllUserBlackListAll: 'user/celarAllUserBlackListAll',
        tequan_url: 'user/tequan',
        orders_url: 'user/orders',
    };

    var Controller = {
        index: function () {
            ea.table.render({
                init: init,
                toolbar:['refresh',
                    [{
                        text: '批量清除特权',
                        url: init.removeVip,
                        method: 'request',
                        auth: 'removeVip',
                        checkbox: true,
                        class: 'layui-btn layui-btn-success layui-btn-sm',
                        icon: 'fa fa-minus ',
                        extend: 'data-full="true"',
                    },
                    {
                        text: '批量清除黑名单',
                        url: init.celarAllUserBlackList,
                        method: 'request',
                        auth: 'celarAllUserBlackList',
                        checkbox: true,
                        class: 'layui-btn layui-btn-danger layui-btn-sm',
                        icon: 'fa fa-minus ',
                        extend: 'data-full="true"',
                    },
                    {
                        text: '批量特权',
                        url: init.tequan_url,
                        method: 'open',
                        auth: 'tequan',
                        checkbox: true,
                        id: 'id',
                        class: 'layui-btn layui-btn-normal layui-btn-sm',
                        icon: 'fa fa-minus ',
                        extend: 'data-full="true"',
                    },{
                        text: '清除全平台特权',
                        url: init.removeVipAll,
                        method: 'request',
                        auth: 'removeVipAll',
                        class: 'layui-btn layui-btn-success layui-btn-sm',
                        icon: 'fa fa-minus ',
                        extend: 'data-full="true"',
                    },
                    {
                        text: '清除全平台黑名单',
                        url: init.celarAllUserBlackListAll,
                        method: 'request',
                        auth: 'celarAllUserBlackListAll',
                        class: 'layui-btn layui-btn-danger layui-btn-sm',
                        icon: 'fa fa-minus ',
                        extend: 'data-full="true"',
                    }
                   ]
                ],
                cols: [[
                    {type: 'checkbox'},
                    {width: 20, field: 'id', title: 'ID'},
                    {width: 120, field: 'phone', title: '手机'},
                    {width: 120, field: 'nickname', title: '昵称'},
                    {width: 120, field: 'avatar', title: '头像',search: false,templet: ea.table.image},
                    {width: 250, align: 'left' ,field: 'payee', title: '银行卡信息'},
                    {width: 180, field: 'recommender', title: '推荐人',search: false},
                    {field: 'state', title: '状态',search: false,
                        templet: function(d){
                            if(d.state == 1){
                                return "<a class='layui-btn layui-btn-normal' data-request='user/updatestate?id="+d.id+"' data-title='确定开启关闭用户状态吗？' data-table='currentTableRenderId'>开</a>";
                            }else{
                                return "<a class='layui-btn layui-btn-danger' data-request='user/updatestate?id="+d.id+"' data-title='确定开启用户状态吗？' data-table='currentTableRenderId'>关</a>";
                            }
                        }
                    },
                    {field: 'edit_bank_access', title: '银行卡',search: false,
                        templet: function(d){
                            if(d.edit_bank_access == 1){
                                return "<a class='layui-btn layui-btn-normal' data-request='user/updatebank?id="+d.id+"' data-title='确定要开通关闭编辑银行卡权限吗?' data-table='currentTableRenderId'>是</a>";
                            }else{
                                return "<a class='layui-btn layui-btn-danger' data-request='user/updatebank?id="+d.id+"' data-title='确定要开通编辑银行卡权限吗？' data-table='currentTableRenderId'>否</a>";
                            }
                        }
                    },
                    
                    {field: 'bad', title: '恶意用户',search: false,
                        templet: function(d){
                            if(d.bad == 1){
                                return "<a class='layui-btn layui-btn-normal' data-request='user/updatebad?id="+d.id+"' data-title='确定要将用户取消恶意用户?' data-table='currentTableRenderId'>是</a>";
                            }else{
                                return "<a class='layui-btn layui-btn-danger' data-request='user/updatebad?id="+d.id+"' data-title='确定要将用户设为恶意用户？' data-table='currentTableRenderId'>否</a>";
                            }
                          
                        }
                    },
                    // {field: 'has_read_protocol', title: '阅读协议',search: false,
                    //     templet: function(d){
                    //         if(d.has_read_protocol == 1){
                    //             return "是";
                    //         }else{
                    //             return '否';
                    //         }
                    //     }
                    // },
                    {field: 'bucket', title: '分仓类型',search: false},
                    // {field: 'is_admin', title: '管理员',search: false},
                    {width: 100, field: 'sign', title: '签名',search: false,templet: ea.table.image},
                    {width: 250, title: '操作', 
                    // templet: ea.table.tool
                    templet: function (row) {
                        return ea.table.tool(row, {
                            init, // 初始化的数据变量
                            operat: [
                                [{
                                    text: '权限设置',
                                    url: init.quanxian,
                                    method: 'open',
                                    auth: 'quanxian',
                                    class: 'layui-btn layui-btn-xs layui-btn-success',
                                    extend: 'data-full="true"',
                                },
                                {
                                    text: '订单查看',
                                    url: init.orders_url,
                                    method: 'open',
                                    auth: 'orders',
                                    class: 'layui-btn layui-btn-xs layui-btn-success',
                                    extend: 'data-full="true"',
                                },
                                ],'edit','delete']
                        })
                     },
                },
                ]],
            });
            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        quanxian: function () {
            ea.listen();
        },
        tequan: function (){
            ea.listen();
        },
        orders: function (){
            ea.listen();
        },
    };
    return Controller;
});
